import { useState, useEffect } from "react";
import {
  loadDepartmentsAPI,
  loadDoctorsAPI,
  loadTagsAPI,
  loadTitlesAPI,
} from "../services/doctors";
import { dalImg } from "../utils/tools";

/**
 * 自定一个hooks
 * @returns
 */
export function useDoctorData() {
  const [banners, setBanners] = useState([]);
  const [categories, setCategories] = useState([]);
  const [departments, setDepartments] = useState([]);
  const [titles, setTitles] = useState([]);
  const [tags, setTags] = useState([]);
  useEffect(() => {
    loadDepartmentsAPI().then((res) => {
      setDepartments(res.data);
    });
    loadTitlesAPI().then((res) => {
      setTitles(res.data);
    });
  }, []);

  useEffect(() => {
    // 初始化的时候获取数据
    loadDoctorsAPI().then((res) => {
      setBanners(res.data.list);
    });
    // loadCategoriesAPI().then((res) => {
    //   setCategories(
    //     res.data.map((item: any) => ({
    //       ...item,
    //       coverImage: dalImg(item.coverImage),
    //     }))
    //   );
    // });
  }, []);

  return { banners, categories, departments, titles };
}
